package com.skeleton.server.user.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.skeleton.common.base.dto.ResultDto;
import com.skeleton.common.base.service.impl.BaseServiceImpl;
import com.skeleton.db.dao.IUserAttentionDao;
import com.skeleton.db.dto.UserAttentionDto;
import com.skeleton.db.entity.UserAttention;
import com.skeleton.server.user.service.IUserAttentionService;
import com.skeleton.utils.ErrorMsgConstants;

@Service
public class UserAttentionServiceImpl extends BaseServiceImpl implements IUserAttentionService {

	@Resource
	private IUserAttentionDao iUserAttentionDao;

	@Override
	public ResultDto doAddAttention(UserAttentionDto baDto) {
		logger.debug("-------UserAttentionServiceImpl---doAddAttention-----------------");
		ResultDto rd = new ResultDto();

		UserAttention uaEntity = baDto.toEntity();

		UserAttention ua = iUserAttentionDao.selectOneById(uaEntity);
		if (ua == null) {
			iUserAttentionDao.insert(uaEntity);
			rd.setSuccess(true);
		} else {
			rd.setSuccess(false);
			rd.setErrorMSG(ErrorMsgConstants.ERR_USER_ATTENTION_HAS);
		}

		return rd;
	}

}
